package com.asialjim.wechat.official.starter.config;

import com.asialjim.wechat.apiservice.constant.WeChatConstants;
import com.asialjim.wechat.spring.config.WeChatApiConfigProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * <h1><em>ASIAL JIM JAVA DOC</em></h1><hr/>
 * <h2>CLASS DESCRIPTION <i>[ NAME: WeChatApiAutoConfig ]</i></h2><strong>
 * <p> we chat api auto config
 * </strong><p><p><em>Copyright &copy; Asial Jim Co., LTD</em><hr/>
 *
 * @author Asial Jim &nbsp;&nbsp; <span>Email:<a href="mailto:asialjim@hotmail.com">asialjim@hotmail.com</a> &nbsp;&nbsp; <a href="asialjim@qq.com">asialjim@qq.com</a></span>
 * @version 1.0.0
 * @since 2021/3/30   &nbsp;&nbsp; JDK 8
 */
@Configuration
@EnableConfigurationProperties(WeChatApiAutoConfigProperties.class)
public class WeChatApiAutoConfig {

    @Bean
    @ConditionalOnClass(WeChatApiAutoConfigProperties.class)
    public WeChatApiConfigProperties weChatApiConfigProperties(WeChatApiAutoConfigProperties properties){
        return properties.properties();
    }

    @Bean
    @ConditionalOnMissingBean(WeChatApiAutoConfigProperties.class)
    public WeChatApiConfigProperties weChatApiConfigProperties(){
        return WeChatApiConfigProperties.builder()
                .weChatApiMaxRetry(3)
                .tempDirFilePath(WeChatApiConfigProperties.DEFAULT_TEMP_FILE_PATH)
                .domain(WeChatConstants.WeChatApiDomain.COMMON_DOMAIN)
                .build();
    }
}
